// 心态 循环请求数据 property: Promise,
export default function () {
    return {
        timer: undefined,
        running: undefined,
        run: function (callback, time = 1000) {
            clearTimeout(this.timer);
            const interval = time;
            this.running = true
            async function _getAPI() {
                if (this.running) {
                    callback && await callback();
                    _next.call(this);
                }
            }
            function _next() {
                this.timer = setTimeout(() => {
                    _getAPI.call(this);
                }, interval);
            }
            _getAPI.call(this);
        },

        _cancel: function () {
            this.running = undefined;
            clearTimeout(this.timer);
        }
    }
}